package com.example.javamaday.leetcode;

public class LeetCodeTest0011 {

    public static void main(String[] args) {

    }

    /**
     * 时间复杂度 O(n)
     */
    public int maxArea(int[] height) {
        int maxResult = 0;
        for (int i = 0, j = height.length - 1; i < j; ) {
            maxResult = Math.max(maxResult, (Math.min(height[i], height[j]) * (j - i)));
            if (height[i] < height[j]) {
                i++;
            } else {
                j--;
            }
        }
        return maxResult;
    }

    /**
     * 时间复杂度 O(n^2)
     */
    public int maxAreaN2(int[] height) {
        int maxResult = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = height.length - 1; j > i; j--) {
                maxResult = Math.max(maxResult, (Math.min(height[i], height[j]) * (j - i)));
            }
        }
        return maxResult;
    }

}